﻿using System;
using System.IO;
using System.Text;
using System.Xml;
using Graphe.Collations;

namespace Graphe.AutomatedTesting.UnitTests.Collations
{
    public class CollationTestClass
    {


        protected string RenderICollationElementToXml(Graphe.Collations.ICollationElement collationElement)
        {
            string xml = null;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (XmlTextWriter writer = new System.Xml.XmlTextWriter(memoryStream, Encoding.Unicode))
                {
                    collationElement.Render(writer);
                    writer.Flush();
                    memoryStream.Position = 0;

                    using (System.IO.StreamReader reader = new StreamReader(memoryStream))
                    {
                        xml = reader.ReadToEnd();
                    }
                }
            }

            return xml;
        }

        protected void ParseICollationElementFromXml(ICollationElement element, out CollationDebugMessages debugMessages, string xml)
        {
            XmlTextReader xmlReader = new XmlTextReader(xml, XmlNodeType.Element, null);
            debugMessages = new CollationDebugMessages();

            xmlReader.Read();

            element.Parse(xmlReader, debugMessages);
        }

    }
}
